/**
 * @description: 通知任务队列
 * @version: 0.0.1
 * @author: xiech
 * @Date: 2023-06-05 10:12:28
 */

import { Processor, IProcessor, Context } from '@midwayjs/bull';
import { Inject } from '@midwayjs/core';
import { DingtalkRobotService } from "../service/dingtalk.robot.service";
import { DingtalkRobotLogsService} from "../service/dingtalk.robot.logs.service";

@Processor('AlarmTask',{
  repeat: {
    cron: '0 0 10 * * ?'
  }
})
export class AlarmTaskProcessor implements IProcessor {

  @Inject()
  ctx: Context;

  @Inject()
  DingtalkRobotService: DingtalkRobotService;

  @Inject()
  DingtalkRobotLogsService: DingtalkRobotLogsService;

  async execute(params: any) {
    return new Promise<void>(async resolve => {
      await this.DingtalkRobotService.scheduleTasks();
      //  删除一周之前的日志
      await this.DingtalkRobotLogsService.delWeekagoLogs();
      resolve();
    })
  }
}
